package com.ruoyi.user.api;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.huanxing.EMServiceUtil;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.ProjectConstant;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.thread.TaskAsync;
import com.ruoyi.user.domain.User;
import com.ruoyi.user.domain.UserProject;
import com.ruoyi.user.pojo.AppConsultantAuth;
import com.ruoyi.user.pojo.AppRegister;
import com.ruoyi.user.pojo.AppUserDetail;
import com.ruoyi.user.pojo.AppUserInfo;
import com.ruoyi.user.pojo.AppUserParam;
import com.ruoyi.user.pojo.AppUserPersonal;
import com.ruoyi.user.service.AppUserService;
import com.ruoyi.user.service.IUserService;

import io.swagger.annotations.Api;

/**
 * 	用户相关API
 * @author DEREK
 *
 */
@RestController
@RequestMapping("/api/v1/user")
@Api(tags = "【APP】用户相关接口")
@CrossOrigin
public class AppUserController {

	@Autowired
	private AppUserService appUserService;
	@Autowired
	private EMServiceUtil eMServiceUtil;
	@Autowired
	private IUserService userService;
	@Autowired
	private TaskAsync taskAsync;
	
	@GetMapping(value = "/updateApple")
	public AjaxResult updateApple() {
		taskAsync.appleRefund(1L);
		return AjaxResult.success();
	}
	
	
	/**
	 * 	修改用户设备号
	 * @param userDetail
	 * @return
	 */
	@PostMapping(value = "/updateDeviceId")
	public AjaxResult updateDeviceId(@RequestBody AppUserDetail userDetail) {
		if(null == userDetail || StringUtils.isEmpty(userDetail.getDeviceId())) {
			return AjaxResult.error("设备号为空");
		}
		return appUserService.updateDeviceId(userDetail.getDeviceId());
	}
	
	
	
	@GetMapping(value = "/updateTest")
	public AjaxResult updateTest() {
		List<User> list = userService.list(new LambdaQueryWrapper<User>().eq(User::getEnabled,3)
				.select(User::getId,User::getVirtuallyDistance));
		list.stream().forEach(user ->{
			Random r =new Random();
			int i = (r.nextInt(20)+1);
			user.setVirtuallyDistance(i);
		});
		userService.updateBatchById(list);
		return AjaxResult.success();
	}
	
	
	
	@GetMapping(value = "/sendMsgTest")
	public AjaxResult sendMsgTest(Long userId,Long toUserId,String form,String toU) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("myHeadPic", "https://quex1017.oss-cn-hangzhou.aliyuncs.com/images/170556662669213.png");
		map.put("myName", "nb92hs");
		map.put("myName_custom", "爆炸大妈57");
		map.put("userId_my", "152");
		map.put("userId_your", "160");
		map.put("your", "tx92vi");
		map.put("yourHeadPic", "https://quex1017.oss-cn-hangzhou.aliyuncs.com/images/1706175246138142.png");
		map.put("your_custom", "爆炸小爸96");
		Set<String> setIds = new HashSet<String>();
		setIds.add(toU);
		//eMServiceUtil.sendUserChat("nb92hs", setIds, map);
		eMServiceUtil.sendSystemMsg(form, "后台发送的消息111", setIds, map);
		return AjaxResult.success();
	}
	
	
	
	/**
	 * 	手机号码登录/注册
	 * @param appRegister
	 * @return
	 */
	@PostMapping(value = "/login")
	public AjaxResult login(@RequestBody AppRegister appRegister,HttpServletRequest request) {
		if(null == appRegister){ return AjaxResult.error("请输入手机号码");	}
		if(StringUtils.isEmpty(appRegister.getMobile())) { return AjaxResult.error("请输入手机号码");	}
		appRegister.setMobile(appRegister.getMobile().replace(" ", ""));
		if(StringUtils.isEmpty(appRegister.getMobile())) { return AjaxResult.error("请输入手机号码");	}
		if(!appRegister.getMobile().startsWith("1")) { return AjaxResult.error("请输入正确的手机号码"); }
		if(appRegister.getMobile().length() != 11) { return AjaxResult.error("请输入正确的手机号码"); }
		if(null == appRegister.getType()) {
			appRegister.setType(0);
		}
		if(0 == appRegister.getType()) {
			if(StringUtils.isEmpty(appRegister.getMobileCode())) { return AjaxResult.error("请输入验证码"); }
		}else {
			if(StringUtils.isEmpty(appRegister.getMobileCode())) { return AjaxResult.error("请输入密码"); }
		}
		return appUserService.login(appRegister.getMobile(),appRegister.getMobileCode(),appRegister.getType(),request);
	}
	
	@PostMapping(value = "/resetPassword")
	public AjaxResult resetPassword(@RequestBody AppRegister appRegister) {
		if(null == appRegister){ return AjaxResult.error("请输入手机号码");	}
		if(StringUtils.isEmpty(appRegister.getMobile())) { return AjaxResult.error("请输入手机号码");	}
		appRegister.setMobile(appRegister.getMobile().replace(" ", ""));
		if(StringUtils.isEmpty(appRegister.getMobile())) { return AjaxResult.error("请输入手机号码");	}
		if(!appRegister.getMobile().startsWith("1")) { return AjaxResult.error("请输入正确的手机号码"); }
		if(appRegister.getMobile().length() != 11) { return AjaxResult.error("请输入正确的手机号码"); }
		if(StringUtils.isEmpty(appRegister.getPassword())) { return AjaxResult.error("请输入密码"); }
		
		return appUserService.resetPassword(appRegister.getMobile(),appRegister.getMobileCode(),appRegister.getPassword());
	}

	/**
	 * 	一键登录
	 * @param appRegister
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/oneClickLogin")
	public AjaxResult oneClickLogin(@RequestBody AppRegister appRegister,HttpServletRequest request) {
		if(null == appRegister){ return AjaxResult.error("请输入手机号码");	}
		if(StringUtils.isEmpty(appRegister.getAccessToken()) ) {
			return AjaxResult.error("手机号码获取失败");
		}
		return appUserService.oneClickLogin(appRegister.getAccessToken(),request);
	}

	/**
	 * 	完善用户信息
	 * @param appRegister
	 * @param request
	 * @return 
	 */
	@PostMapping(value = "/completeUserInfo")
	public AjaxResult completeUserInfo(@RequestBody AppRegister appRegister,HttpServletRequest request) {
		if(null == appRegister) { return AjaxResult.error("请输入参数"); }
		if(null == appRegister.getUserId()) { return AjaxResult.error("请输入用户ID"); }
		if(StringUtils.isEmpty(appRegister.getBirthday())) { return AjaxResult.error("请输入用户生日"); }
		if(StringUtils.isEmpty(appRegister.getSex())) {	return AjaxResult.error("请输入用户性别"); }
		if(StringUtils.isEmpty(appRegister.getHeadPic())){ 
			Random r = new Random() ;
			if("F".equalsIgnoreCase(appRegister.getSex())) {
				ProjectConstant.femaleList.get(r.nextInt(2));
			}else {
				ProjectConstant.maleList.get(r.nextInt(2));
			}
		}
		if(StringUtils.isEmpty(appRegister.getNickName())) { return AjaxResult.error("请输入用户昵称");}
		/**
		 * 	完善信息的经度：112.9929069010417
			完善信息的纬度：28.16903862847222
		 */
		System.out.println("完善信息的经度："+appRegister.getLongitude());
		System.out.println("完善信息的纬度："+appRegister.getLatitude());
		return appUserService.completeUserInfo(appRegister,request);
	}

	/**
	 * 	微信登录
	 * @param appRegister
	 * @return
	 */
	@PostMapping(value = "/wechatLogin")
	public AjaxResult wechatLogin(@RequestBody AppUserParam param,HttpServletRequest request) {
		if(null == param) { return AjaxResult.error("参数为空"); }
		if (CommonUtil.isEmpty(param.getUnionId())) { return AjaxResult.error("unionId不能为空"); }
		if (CommonUtil.isEmpty(param.getOpenId())) { return AjaxResult.error("openId不能为空");	}
		return appUserService.wechatLogin(param.getUnionId(),param.getOpenId(),request);
	}

	/**
	 * 	苹果授权登录
	 * @param request
	 * @param appRegisterVO
	 * @return
	 */
	@PostMapping(value = "/appleLogin")
	public AjaxResult appleLogin(@RequestBody AppUserParam param,HttpServletRequest request) {
		if(null == param) { return AjaxResult.error("参数为空"); }
		if (CommonUtil.isEmpty(param.getAppleId())) { return AjaxResult.error("appleId 不能为空");}
		return appUserService.appleLogin(param.getAppleId(),request);
	}

	/**
	 * 	绑定手机号码
	 * @param appRegister
	 * @return
	 */
	@PostMapping(value = "/bindingMobile")
	public AjaxResult bindingMobile(@RequestBody AppUserParam param,HttpServletRequest request) {
		if(null == param) { return AjaxResult.error("参数为空"); }
		if (CommonUtil.isEmpty(param.getUnionId()) && CommonUtil.isEmpty(param.getOpenId()) && CommonUtil.isEmpty(param.getAppleId())) {	return AjaxResult.error("唯一Id不能为空");}
		if(StringUtils.isEmpty(param.getMobile())) { return AjaxResult.error("请输入手机号码");	}
		param.setMobile(param.getMobile().replace(" ", ""));
		if(StringUtils.isEmpty(param.getMobile())) { return AjaxResult.error("请输入手机号码");	}
		if(!param.getMobile().startsWith("1")) { return AjaxResult.error("请输入正确的手机号码"); }
		if(param.getMobile().length() != 11) { return AjaxResult.error("请输入正确的手机号码"); }
		if(StringUtils.isEmpty(param.getMobileCode())) { return AjaxResult.error("请输入验证码"); }
		return appUserService.bindingMobile(param.getMobile(),param.getMobileCode(),param.getUnionId(),param.getOpenId(),param.getAppleId(),request);
	}

	/**
	 * 	添加用户使用意图
	 * @param name
	 * @return
	 */
	@PostMapping(value = "/addUserPurpose")
	public AjaxResult addUserPurpose(@RequestBody AppUserParam param) {
		if(null == param) { return AjaxResult.error("参数为空"); }
		if (CommonUtil.isEmpty(param.getName())) { return AjaxResult.error("请选择标签"); }
		return appUserService.addUserPurpose(param.getName());
	}


	/**
	 * 	输入邀请码绑定
	 * @param inviteCode
	 * @return
	 */
	@PostMapping(value = "/bindInviteCode")
	public AjaxResult bindInviteCode(@RequestBody AppUserParam param) {
		if(null == param) { return AjaxResult.error("参数为空"); }
		if (CommonUtil.isEmpty(param.getInviteCode())) { return AjaxResult.error("请输入邀请码"); }
		return appUserService.bindInviteCode(param.getInviteCode());
	}

	/**
	 * 	更新用户经纬度
	 * @param loginUserId	当前登录用户ID
	 * @param longitude		经度
	 * @param latitude		纬度
	 * @return
	 */
	@PostMapping(value = "/updUserLongitude")
	public AjaxResult updUserLongitude(@RequestBody AppUserParam param,HttpServletRequest request) {
		if(null == param) { return AjaxResult.error("参数为空"); }
		return appUserService.updUserLongitude(param.getLongitude(),param.getLatitude(),param.getCity(),param.getCityCode(),request);
	}

	/**
	 * 	用户详情
	 * @param userId
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/userDetail")
	public AjaxResult userDetail(@RequestBody AppUserParam param,HttpServletRequest request) {
		if(null == param) { return AjaxResult.error("参数为空"); }
//		if(StringUtils.isEmpty(param.getLongitude()) || StringUtils.isEmpty(param.getLatitude())) {
//			//return AjaxResult.error(500181,"请开启定位");
//			param.setLongitude("112");
//			param.setLatitude("28");
//		}
		return appUserService.userDetail(param.getUserId(),param.getLongitude(),param.getLatitude(),request);
	}

	/**
	 * 	用户订单评价列表
	 * @param toUserId
	 * @param pageNo
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/userOrderEvaluateList")
	public AjaxResult userOrderEvaluateList(Long toUserId,Integer pageNo,HttpServletRequest request) {
		if(null == toUserId) { return AjaxResult.error("请输入对方ID"); }
		if(null == pageNo) pageNo = 1;
		return appUserService.userOrderEvaluateList(toUserId,pageNo,request);
	}
	
	/**
	 * 	获取用户是否是VIP
	 * @param toUserId
	 * @return
	 */
	@GetMapping(value = "/getIsVip")
	public AjaxResult getIsVip(Long toUserId) {
		return appUserService.getIsVip(toUserId);
	}


	/**
	 * 	查询用户相册
	 * @param userId
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/qryUserPhoto")
	public AjaxResult qryUserPhoto(Long userId,HttpServletRequest request) {
		if(null == userId) { return AjaxResult.error("参数为空"); }
		return appUserService.qryUserPhoto(userId,request);
	}

	/**
	 * 	删除用户相册
	 * @param userId
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/delUserPhoto")
	public AjaxResult delUserPhoto(@RequestBody AppUserParam param,HttpServletRequest request) {
		if(null == param) { return AjaxResult.error("参数为空"); }
		return appUserService.delUserPhoto(param.getPhotoId(),request);
	}

	/**
	 * 	添加用户相册
	 * @param userId
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/addUserPhoto")
	public AjaxResult addUserPhoto(@RequestBody AppUserParam param,HttpServletRequest request) {
		if(null == param) { return AjaxResult.error("参数为空"); }
		return appUserService.addUserPhoto(param.getPhotoList(),request);
	}

	/**
	 * 	我的关联数据 粉丝、关注、访客、足迹
	 * @param param
	 * @return
	 */
	@GetMapping(value = "/myCorrelationList")
	public AjaxResult myCorrelationList(Integer type,Integer pageNo) {
		if(null == type) type = 1;
		if(null == pageNo) pageNo = 1; 
		return appUserService.myCorrelationList(type,pageNo);
	}

	/**
	 * 	用户关注或者取消关注 
	 * @param userId
	 * @param type		1= 关注  2=取消关注 
	 * @return
	 */
	@PostMapping(value = "/concernOperation")
	public AjaxResult concernOperation(@RequestBody AppUserParam param) {
		if(null == param) { return AjaxResult.error("参数为空"); }
		if(null == param.getUserId() || null == param.getType()) {
			return AjaxResult.error("参数不能为空");
		}
		return appUserService.concernOperation(param.getUserId(),param.getType());
	}


	/**
	 * 	查询个人信息
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/qryUserInfo")
	public AjaxResult qryUserInfo(HttpServletRequest request) {
		return appUserService.qryUserInfo(request);
	}

	/**
	 * 	修改个人信息
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/editUserInfo")
	public AjaxResult editUserInfo(@RequestBody AppUserInfo userInfo,HttpServletRequest request) {
		if(null == userInfo) {
			return AjaxResult.error("请输入用户信息");
		}
		if(StringUtils.isEmpty(userInfo.getNickName())) {
			return AjaxResult.error("请输入昵称");
		}
		return appUserService.editUserInfo(userInfo,request);
	}

	/**
	 * 	用户个人中心
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/userPersonal")
	public AjaxResult userPersonal(HttpServletRequest request) {
		return appUserService.userPersonal(request);
	}

	/**
	 * 	谁看过我 我看过谁 足迹
	 * @param loginUserId
	 * @param type		1=足迹(我看过谁) 2=来访(谁看过我)
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@PostMapping(value = "/whoHaveIsee")
	public AjaxResult whoHaveIsee(@RequestBody AppUserParam param,HttpServletRequest request) {
		if(null == param) { return AjaxResult.error("参数为空"); }
		if(null == param.getPageNo() || null == param.getType()) {
			return AjaxResult.error("参数不能为空");
		}
		return appUserService.whoHaveIsee(param,request);
	}


	/**
	 * 	拉黑或者取消拉黑
	 * @param loginUserId
	 * @param userId
	 * @return
	 */
	@PostMapping(value = "/blockOrunBlock")
	public AjaxResult blockOrunBlock(@RequestBody AppUserInfo userInfo,HttpServletRequest request) {
		if(null == userInfo || null == userInfo.getUserId()) {
			return AjaxResult.error("请选择用户");
		}
		return appUserService.blockOrunBlock(userInfo.getUserId(),request);
	}

	/**
	 * 	我的黑名单列表
	 * @param pageNo
	 * @return
	 */
	@GetMapping(value = "/myBlacklist")
	public AjaxResult myBlacklist(@RequestParam(value = "pageNo", required = false, defaultValue = "1")Integer pageNo,HttpServletRequest request) {
		return appUserService.myBlacklist(pageNo,request);
	}

	/**
	 * 	我的钱包
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/myWallet")
	public AjaxResult myWallet(HttpServletRequest request) {
		return appUserService.myWallet(request);
	}

	/**
	 * 	解锁用户微信
	 * @param userInfo.userId		用户ID
	 * @param userInfo.type			1=第一次点击 2=付款
	 * @return
	 */
	@PostMapping(value = "/unlockUserWechat")
	public AjaxResult unlockUserWechat(@RequestBody AppUserInfo userInfo) {
		if(null == userInfo || null == userInfo.getUserId()) {
			return AjaxResult.error("请选择用户");
		}
		if(null == userInfo.getType()) {
			userInfo.setType(1);
		}
		return appUserService.unlockUserWechat(userInfo);
	}
	
	/**
	 * 	解锁用户聊天
	 * @param userInfo.userId		用户ID
	 * @param userInfo.type			1=第一次点击 2=付款
	 * @return
	 */
	@PostMapping(value = "/unlockUserChat")
	public AjaxResult unlockUserChat(@RequestBody AppUserInfo userInfo) {
		if(null == userInfo || null == userInfo.getUserId()) {
			return AjaxResult.error("请选择用户");
		}
		if(null == userInfo.getType()) {
			userInfo.setType(1);
		}
		return appUserService.unlockUserChat(userInfo);
	}


	/**
	 * 	获取咨询师认证资料
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/getConsultantAuthInfo")
	public AjaxResult getConsultantAuthInfo(HttpServletRequest request) {
		return appUserService.getConsultantAuthInfo(request);
	}

	/**
	 * 	修改咨询师认证资料
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/editConsultantAuthInfo")
	public AjaxResult editConsultantAuthInfo(@RequestBody AppConsultantAuth consultantAuth,HttpServletRequest request) {
		if(null == consultantAuth) {
			return AjaxResult.error("请输入参数");
		}
		return appUserService.editConsultantAuthInfo(consultantAuth,request);
	}

	/**
	 * 	咨询师详情 - 设置标签或者语音或者服务类型
	 * @param user
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/setLableOrVoiceOrServiceType")
	public AjaxResult setLableOrVoiceOrServiceType(@RequestBody AppUserDetail user,HttpServletRequest request) {
		if(null == user) {
			return AjaxResult.error("请填写数据");
		}
		return appUserService.setLableOrVoice(user,request);
	}

	/**
	 * 	新增或修改咨询项目
	 * @param userProject
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/addConsultantProject")
	public AjaxResult addConsultantProject(@RequestBody UserProject userProject,HttpServletRequest request) {
		if(null == userProject) {
			return AjaxResult.error("请输入参数");
		}
		return appUserService.addConsultantProject(userProject,request);
	}

	/**
	 * 	获取咨询项目详情
	 * @param id
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/getConsultantProjectDetail")
	public AjaxResult getConsultantProjectDetail(Long id,HttpServletRequest request) {
		if(null == id) {
			return AjaxResult.error("请选择项目");
		}
		return appUserService.getConsultantProjectDetail(id,request);
	}

	/**
	 * 	获取充值记录
	 * @return
	 */
	@GetMapping(value = "/getRechargeRecord")
	public AjaxResult getRechargeRecord(Integer pageNo) {
		if(null == pageNo) pageNo = 1; 
		return appUserService.getRechargeRecord(pageNo);
	}

	/**
	 * 	获取咨询项目列表
	 * @param pageNo
	 * @param lable
	 * @return
	 */
	@GetMapping(value = "/getConsultantProjectList")
	public AjaxResult getConsultantProjectList(Integer pageNo,String lable) {
		if(null == pageNo) pageNo = 1; 
		return appUserService.getConsultantProjectList(pageNo,lable);
	}
	
//	@Autowired
//	private IUserService userService;
	@GetMapping(value = "/ramdoLableByUser")
	public AjaxResult ramdoLableByUser() {
//		String[] split = {"电竞","电影","唱K","美食","剧本杀","密室逃脱","机车","二次元","蹦迪","旅行","运动健身","摄影"};
//		List<User> list = userService.list(new LambdaQueryWrapper<User>().eq(User::getEnabled, 3));
//		for (User user : list) {
//			//user.setInteName(ramdoLable(split, 0, 11));
//		}
//		userService.updateBatchById(list);
		return AjaxResult.success();
	}

	public String ramdoLable(String[] split,int minValue,int maxValue) {
		Random random = new Random();
		String s = "";
		while (true) {
			int randomInt = random.nextInt(maxValue - minValue + 1) + minValue;
			String c = split[randomInt];
			//System.out.println("s:"+s);
			//System.out.println("c:"+c);
			if(s.contains(c)) {
				continue;
			}
			s += c+",";
			if(s.split(",").length == 3) {
				break;
			}
		}
		return s.substring(0,s.length()-1);
	}
	
	public static void main(String[] args) {
		//String[] split = {"电竞","电影","唱K","美食","剧本杀","密室逃脱","机车","二次元","蹦迪","旅行","运动健身","摄影"};
		
	}
	
	/**
	 * 	设置微信号
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/setWechat")
	public AjaxResult setWechat(@RequestBody AppUserDetail user,HttpServletRequest request) {
		if(null == user || StringUtils.isEmpty(user.getWechat())) {
			return AjaxResult.error("请填写微信号");
		}
		return appUserService.setWechat(user.getWechat(),request);
	}
	
	/**
	 * 	设置语音地址
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/setVoice")
	public AjaxResult setVoice(@RequestBody AppUserDetail user,HttpServletRequest request) {
		if(null == user || StringUtils.isEmpty(user.getVoice())) {
			return AjaxResult.error("请录制语音");
		}
		return appUserService.setVoice(user.getVoice(),request);
	}
	
	/**
	 * 	获取解锁微信列表
	 * @param pageNo
	 * @return
	 */
	@GetMapping(value = "/getUnlockWechatList")
	public AjaxResult getUnlockWechatList(Integer pageNo) {
		if(null == pageNo) pageNo = 1; 
		return appUserService.getUnlockWechatList(pageNo);
	}
	
	
	/**
	 * 	获取用户定位
	 * @param userId
	 * @return
	 */
	@GetMapping(value = "/getUserLocate")
	public AjaxResult getUserLocate(Long userId) {
		return appUserService.getUserLocate(userId);
	}
	
	/**
	 * 	设置青少年模式是否开启
	 * @param user.isYoung		0=关闭 1=开启
	 * @param user.youngPwd		密码
	 * @return
	 */
	@PostMapping(value = "/setTeenageMode")
	public AjaxResult setTeenageMode(@RequestBody AppUserPersonal user) {
		if(null == user.getIsYoung()) {
			user.setIsYoung(0);
		}
		return appUserService.setTeenageMode(user.getIsYoung(),user.getYoungPwd());
	}
	
	/**
	 * 	校验用户是否能发送消息
	 * @return
	 */
	@PostMapping(value = "/checkUserIsMsgSend")
	public AjaxResult checkUserIsMsgSend(HttpServletRequest request,Long toUserId) {
		return appUserService.checkUserIsMsgSend(request,toUserId);
	}
	
	
	@GetMapping(value = "/updUserDetailedAddress")
	public AjaxResult updUserDetailedAddress(Long toUserId) {
		User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getId, toUserId)
				.select(User::getId,User::getLoginPointX,User::getLoginPointY));
		if(null != user && null != user.getLoginPointX() && null != user.getLoginPointY()) {
			BigDecimal longitude = user.getLoginPointX().setScale(6, BigDecimal.ROUND_DOWN);
			BigDecimal latitude = user.getLoginPointY().setScale(6, BigDecimal.ROUND_DOWN);
			String detailedAddress = HttpUtils.getDetailedAddress(longitude, latitude);
			if(!"fail".equals(detailedAddress)) {
				user.setDetailAddress(detailedAddress);
				userService.updateById(user);
				return AjaxResult.success("成功",detailedAddress);
			}
		}
		return AjaxResult.error("用户不存在经纬度");
	}
	
}
